package com.example.rpcdemo.config;

import com.example.rpccommon.client.RpcClient;
import com.example.rpccommon.config.ServiceDiscovery;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class RpcConfig {

    @Value("${rpc.address}")
    String serverAddress;

    @Value("${zk.address}")
    String zkAddress;

    @Bean
    public ServiceDiscovery serviceDiscovery(){
        return  new ServiceDiscovery(this.zkAddress);
    }

    @Bean
    public RpcClient rpcClient(ServiceDiscovery serviceDiscovery){
        RpcClient rpcClient=new RpcClient(serverAddress, serviceDiscovery);
        return rpcClient;
    }

}
